package com.xiguthings.waka.service.paper.impl;

import java.util.List;

import com.xiguthings.waka.dao.DataBaseStatus;
import com.xiguthings.waka.dao.mapper.PaperMapper;
import com.xiguthings.waka.exception.BussinessException;
import com.xiguthings.waka.publicUtils.StringUtils;
import com.xiguthings.waka.web.controller.base.AbstractController;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.xiguthings.waka.po.Paper;
import com.xiguthings.waka.po.PaperExample;
import com.xiguthings.waka.po.extpo.Page;
import com.xiguthings.waka.service.paper.IPaperService;

import javax.annotation.Resource;

@Service
@Transactional
public class PaperServiceImpl implements IPaperService {

    @Resource
    private PaperMapper paperMapper;


    @Override
    @Transactional(propagation = Propagation.NOT_SUPPORTED)
    public int countByExample(PaperExample example) throws Exception {
        // TODO Auto-generated method stub
        return 0;
    }

    @Override
    @Transactional(readOnly = false, isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED)
    public int deleteByExample(PaperExample example) throws Exception {
        // TODO Auto-generated method stub
        return 0;
    }

    @Override
    @Transactional(readOnly = false, isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED)
    public int deleteByPrimaryKey(String id) throws Exception {
        int row = paperMapper.deleteByPrimaryKey(id);
        return row;
    }

    @Override
    @Transactional(readOnly = false, isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED)
    public int insert(Paper t) throws Exception {

        if (t == null) {
            BussinessException bet = new BussinessException("不能存入空对象");
            bet.setCode(CODE_EMPTY_REQUIRED);
            throw bet;
        }
        if (StringUtils.isBlank(t.getGrowthId())) {
            BussinessException bet = new BussinessException("growthId为空:必须指明所属的成长维度");
            bet.setCode(CODE_EMPTY_REQUIRED);
            throw bet;
        }
        if (t.getRank() == null) {
            BussinessException bet = new BussinessException("rank为空:排序号为空");
            bet.setCode(CODE_EMPTY_REQUIRED);
            throw bet;
        }
//        if (StringUtils.isBlank(t.getPaperCardId())) {
//            BussinessException bet = new BussinessException("paperCardId为空:必须给予一张奖励的卡片");
//            bet.setCode(CODE_EMPTY_REQUIRED);
//            throw bet;
//        }


        String id = StringUtils.getRandomUUID();
        t.setPaperId(id);
//		t.setStatus(DataBaseStatus.NORMAL);
        int row = paperMapper.insert(t);
        return row;
    }

    @Override
    @Transactional(readOnly = false, isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED)
    public int insertSelective(Paper t) throws Exception {
        // TODO Auto-generated method stub
        return 0;
    }

    @Override
    @Transactional(propagation = Propagation.NOT_SUPPORTED)
    public List<Paper> selectByExample(PaperExample example) throws Exception {
        List<Paper> list = paperMapper.selectByExample(example);
        return list;
    }

    @Override
    @Transactional(propagation = Propagation.NOT_SUPPORTED)
    public Paper selectByPrimaryKey(String id) throws Exception {
        return paperMapper.selectByPrimaryKey(id);
    }

    @Override
    @Transactional(readOnly = false, isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED)
    public int updateByExampleSelective(Paper t, PaperExample example) throws Exception {
        // TODO Auto-generated method stub
        return 0;
    }

    @Override
    @Transactional(readOnly = false, isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED)
    public int updateByExample(Paper t, PaperExample example) throws Exception {
        // TODO Auto-generated method stub
        return 0;
    }

    @Override
    @Transactional(readOnly = false, isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED)
    public int updateByPrimaryKeySelective(Paper t) throws Exception {
        int row = paperMapper.updateByPrimaryKeySelective(t);
        return row;
    }

    @Override
    @Transactional(readOnly = false, isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED)
    public int updateByPrimaryKey(Paper t) throws Exception {
        // TODO Auto-generated method stub
        return 0;
    }

    @Override
    @Transactional(propagation = Propagation.NOT_SUPPORTED)
    public Page selectByPage(Page pageEntity, PaperExample example) throws Exception {
        // TODO Auto-generated method stub
        return null;
    }

}
